<script setup>
import { useRouter } from 'vue-router'
import {ref} from "vue";

import {showToast} from "vant";
import {get} from "../../util/request.js";

const router = useRouter()
const onClickLeft = () => {
  router.go(-1)
}
const active = ref('0');
const collections = ref([{}]);
const changeTab=()=>{
  console.log(active.value)
  get('/user/wallet/findAllByType?type='+active.value).then((response) => {
    console.log(JSON.stringify(response))
    console.log("获取处理器的数据：" + JSON.stringify(response))
    //直接使用响应体
    const {code,data,msg} = response
    if (code == 0) {
      showToast("查询成功");
      collections.value = data;// 初始化界面
      console.log("获取处理器的数据：")
    }else {
      showToast("查询失败"+msg);
    }
  })
}
</script>

<template>
<h1>我叫喻文波</h1>
  <van-nav-bar
      title="我的消息"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
  <van-tabs v-model:active="active" @change="changeTab">

    <van-tab title="消费记录" name="1">
      <van-cell-group>
        <van-list>
          <van-cell v-for="(collection, index) in collections"
          :key="index"
          >
            <template #title>{{collection.id}}</template>
            <template #default>{{collection.money}}</template>
            <template #right-icon>
              来源{{collection.info}}
            </template>
            <template #label>
              {{collection.ctime}}
            </template>

          </van-cell>
        </van-list>
      </van-cell-group>
    </van-tab>
    <van-tab title="支付记录" name="2">
      <van-cell-group>
        <van-list>
          <van-cell v-for="(collection, index) in collections"
                    :key="index"

          >
            <template #title>{{collection.id}}</template>
            <template #default>{{collection.money}}</template>
            <template #right-icon>
              {{collection.info}}
            </template>
            <template #label>
              {{collection.ctime}}
            </template>
          </van-cell>
        </van-list>
      </van-cell-group>
    </van-tab>

  </van-tabs>
</template>

<style scoped>

</style>